﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BuySoftwareOnline.Domain.Abstract;

namespace BuySoftwareOnline.Domain.Concrete
{
    public class OrderRepository : IOrderRepository
    {
        private BuySoftwareOnlineDataContext context;

        public OrderRepository()
        {
            context = new BuySoftwareOnlineDataContext();
        }

        public IQueryable<Order> Orders
        {
            get { return context.Orders; }
        }

        public void SaveOrder(Order order)
        {
            if (order.OrderID == 0)
            {
                context.Orders.InsertOnSubmit(order);
            }
            else
            {
                context.Orders.Attach(order);
                context.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, order);
            }
            context.SubmitChanges();
        }

        public void DeleteOrder(Order order)
        {
            context.Orders.DeleteOnSubmit(order);
            context.SubmitChanges();
        }
    }
}
